package com.petlab.action;

import java.util.ArrayList;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionSupport;
import com.petlab.dao.ApplyRequestSaveDao;
import com.petlab.model.ApplyRequest;
import com.petlab.model.User;

@Component("handleRequestInTheme")
@Scope("prototype")
public class HandleRequestInTheme extends ActionSupport {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private String requestInfo;

	public String getRequestInfo() {
		return requestInfo;
	}

	public void setRequestInfo(String requestInfo) {
		this.requestInfo = requestInfo;
	}

	private String requestPersonEmail;

	public String getRequestPersonEmail() {
		return requestPersonEmail;
	}

	public void setRequestPersonEmail(String requestPersonEmail) {
		this.requestPersonEmail = requestPersonEmail;
	}

	private String adminEmail;

	public String getAdminEmail() {
		return adminEmail;
	}

	public void setAdminEmail(String adminEmail) {
		this.adminEmail = adminEmail;
	}

	private String themeTitle;

	public String getThemeTitle() {
		return themeTitle;
	}

	public void setThemeTitle(String themeTitle) {
		this.themeTitle = themeTitle;
	}

	private String username;

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	private ApplyRequestSaveDao applyRequestSaveDao;

	public ApplyRequestSaveDao getApplyRequestSaveDao() {
		return applyRequestSaveDao;
	}

	@Resource
	public void setApplyRequestSaveDao(ApplyRequestSaveDao applyRequestSaveDao) {
		this.applyRequestSaveDao = applyRequestSaveDao;
	}

	public String execute() throws Exception {

		ApplyRequest applyRequest = new ApplyRequest();
		applyRequest.setRequestPersonEmail(requestPersonEmail);
		applyRequest.setRequestInfo(requestInfo);
		applyRequest.setThemeTitle(themeTitle);
		applyRequest.setUsername(username);

		User user = new User();
		user.setEmail(adminEmail);
		ArrayList<User> users = new ArrayList<User>();
		users.add(user);
		applyRequestSaveDao.save(applyRequest, users);

		return SUCCESS;
	}

}
